<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: KeyboardStudio/KeyboardStudio.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 VGA Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_keyboard_studio_2_keyboard_studio_8ino-example.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">KeyboardStudio/KeyboardStudio.ino</div>  </div>
</div><!--header-->
<div class="contents">
<p>PS/2 keyboard full example (scancodes, virtual keys, LEDs control...)</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - www.fabgl.com</span></div><div class="line"><span class="comment">  Copyright (c) 2019 Fabrizio Di Vittorio.</span></div><div class="line"><span class="comment">  All rights reserved.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  This file is part of FabGL Library.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment">  (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">  GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> printHelp()</div><div class="line">{</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;\n\nPS/2 Keyboard Studio\n&quot;</span>);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;Chip Revision: %d   Chip Frequency: %d MHz\n&quot;</span>, ESP.getChipRevision(), ESP.getCpuFreqMHz());</div><div class="line"></div><div class="line">  printInfo();</div><div class="line"></div><div class="line">  Serial.printf(<span class="stringliteral">&quot;Commands:\n&quot;</span>);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;  1 = US Layout  2 = UK Layout      3 = DE Layout   4 = IT Layout\n&quot;</span>);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;  r = Reset      s = Scancode Mode  a = VirtualKey/ASCII Mode\n&quot;</span>);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;  l = Test LEDs\n&quot;</span>);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;Various:\n&quot;</span>);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;  h = Print This help\n\n&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> printInfo()</div><div class="line">{</div><div class="line">  <span class="keywordflow">if</span> (Keyboard.<a name="a0"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#a5c07c13d95a52b5c8d91a7328fe17930">isKeyboardAvailable</a>()) {</div><div class="line">    Serial.write(<span class="stringliteral">&quot;Device Id = &quot;</span>);</div><div class="line">    <span class="keywordflow">switch</span> (Keyboard.<a name="a1"></a><a class="code" href="classfabgl_1_1_p_s2_device_class.html#a6a3cfd9086abb1d0dda31e5f9c22f40e">identify</a>()) {</div><div class="line">      <span class="keywordflow">case</span> <a name="a2"></a><a class="code" href="group___enumerations.html#gga209a520f6108c21bd313cb2c98fde74aae40a3cdddbf5b1afcf9b75940cb000aa">fabgl::OldATKeyboard</a>:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;Old AT Keyboard\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <a name="a3"></a><a class="code" href="group___enumerations.html#gga209a520f6108c21bd313cb2c98fde74aa4ff15555542ae9bfb6d8540324603608">fabgl::MouseStandard</a>:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;Standard Mouse\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <a name="a4"></a><a class="code" href="group___enumerations.html#gga209a520f6108c21bd313cb2c98fde74aa21c07e6edcf197ea7673afac2bdb6f08">fabgl::MouseWithScrollWheel</a>:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;Mouse with scroll wheel\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <a name="a5"></a><a class="code" href="group___enumerations.html#gga209a520f6108c21bd313cb2c98fde74aa3229d4013ec812e9aeb09bba83568a84">fabgl::Mouse5Buttons</a>:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;5 Buttons Mouse\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <a name="a6"></a><a class="code" href="group___enumerations.html#gga209a520f6108c21bd313cb2c98fde74aa543587ae0352ed1783753c5f24a7f33c">fabgl::MF2KeyboardWithTranslation</a>:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;MF2 Keyboard with translation\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <a name="a7"></a><a class="code" href="group___enumerations.html#gga209a520f6108c21bd313cb2c98fde74aa483120b2f1f56b472fe7752a0a5048a2">fabgl::M2Keyboard</a>:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;MF2 keyboard\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">default</span>:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;Unknown\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    }</div><div class="line">    Serial.printf(<span class="stringliteral">&quot;  Keyboard Layout: \&quot;%s\&quot;\n&quot;</span>, Keyboard.<a name="a8"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#ae7919c90b9cc0af1800b18aba04d0218">getLayout</a>()-&gt;<a name="a9"></a><a class="code" href="structfabgl_1_1_keyboard_layout.html#ab4056289e6b9726900042349a455c41b">name</a>);</div><div class="line">  } <span class="keywordflow">else</span></div><div class="line">    Serial.write(<span class="stringliteral">&quot;Keyboard Error!\n&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup()</div><div class="line">{</div><div class="line">  Serial.begin(115200);</div><div class="line">  delay(500);  <span class="comment">// avoid garbage into the UART</span></div><div class="line">  Serial.write(<span class="stringliteral">&quot;\n\nReset\n&quot;</span>);</div><div class="line"></div><div class="line">  PS2Controller.<a name="a10"></a><a class="code" href="classfabgl_1_1_p_s2_controller_class.html#a7082e498e95fd5f5a4edfbe73923f397">begin</a>(PS2Preset::KeyboardPort0);</div><div class="line"></div><div class="line">  printHelp();</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop()</div><div class="line">{</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">char</span> mode = <span class="charliteral">&#39;a&#39;</span>;</div><div class="line">  <span class="comment">//static fabgl::VirtualKey lastvk = fabgl::VK_NONE; // avoid to repeat last vk</span></div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (Serial.available() &gt; 0) {</div><div class="line">    <span class="keywordtype">char</span> c = Serial.read();</div><div class="line">    <span class="keywordflow">switch</span> (c) {</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;h&#39;</span>:</div><div class="line">        printHelp();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;1&#39;</span>:</div><div class="line">        Keyboard.<a name="a11"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#a08b281a865847dfc514b2f0c7d77e095">setLayout</a>(&amp;fabgl::USLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;2&#39;</span>:</div><div class="line">        Keyboard.<a class="code" href="classfabgl_1_1_keyboard_class.html#a08b281a865847dfc514b2f0c7d77e095">setLayout</a>(&amp;fabgl::UKLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;3&#39;</span>:</div><div class="line">        Keyboard.<a class="code" href="classfabgl_1_1_keyboard_class.html#a08b281a865847dfc514b2f0c7d77e095">setLayout</a>(&amp;fabgl::GermanLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;4&#39;</span>:</div><div class="line">        Keyboard.<a class="code" href="classfabgl_1_1_keyboard_class.html#a08b281a865847dfc514b2f0c7d77e095">setLayout</a>(&amp;fabgl::ItalianLayout);</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;r&#39;</span>:</div><div class="line">        Keyboard.<a name="a12"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#a09ac1cafc7c2b1f2b16fece0f969bfd3">reset</a>();</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;s&#39;</span>:</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;a&#39;</span>:</div><div class="line">        mode = c;</div><div class="line">        Keyboard.<a name="a13"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#a7d79d73d9a71bbe889a89cb6358d64db">suspendVirtualKeyGeneration</a>(c == <span class="charliteral">&#39;s&#39;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;l&#39;</span>:</div><div class="line">      {</div><div class="line">        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 8; ++i) {</div><div class="line">          Keyboard.<a name="a14"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#ae7c233605976b3a37c679f0203210fa4">setLEDs</a>(i &amp; 1, i &amp; 2, i &amp; 4);</div><div class="line">          delay(1000);</div><div class="line">        }</div><div class="line">        delay(2000);</div><div class="line">        <span class="keywordflow">if</span> (Keyboard.<a class="code" href="classfabgl_1_1_keyboard_class.html#ae7c233605976b3a37c679f0203210fa4">setLEDs</a>(0, 0, 0))</div><div class="line">          Serial.write(<span class="stringliteral">&quot;OK\n&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (mode == <span class="charliteral">&#39;s&#39;</span> &amp;&amp; Keyboard.<a name="a15"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#afc84336586414c7b19cd879f96a06583">scancodeAvailable</a>()) {</div><div class="line">    <span class="comment">// scancode mode (show scancodes)</span></div><div class="line">    Serial.printf(<span class="stringliteral">&quot;Scancode = 0x%02X\n&quot;</span>, Keyboard.<a name="a16"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#a56e01f2289d9bb02d19e08fece4c731c">getNextScancode</a>());</div><div class="line">  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (Keyboard.<a name="a17"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#aa93820f1c8f447a37c01376a8d6dbba0">virtualKeyAvailable</a>()) {</div><div class="line">    <span class="comment">// ascii mode (show ASCII and VirtualKeys)</span></div><div class="line">    <span class="keywordtype">bool</span> down;</div><div class="line">    <span class="keyword">auto</span> vk = Keyboard.<a name="a18"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#ae5bcb0c200a35ece54ecdf4cd47e49d6">getNextVirtualKey</a>(&amp;down);</div><div class="line">    <span class="comment">//if (vk != lastvk) {</span></div><div class="line">      Serial.printf(<span class="stringliteral">&quot;VirtualKey = %s&quot;</span>, Keyboard.<a name="a19"></a>virtualKeyToString(vk));</div><div class="line">      <span class="keywordtype">int</span> c = Keyboard.<a name="a20"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#a7fba5778b3518e9aa2d397e0da71520e">virtualKeyToASCII</a>(vk);</div><div class="line">      <span class="keywordflow">if</span> (c &gt; -1) {</div><div class="line">        Serial.printf(<span class="stringliteral">&quot;  ASCII = 0x%02X   &quot;</span>, c);</div><div class="line">        <span class="keywordflow">if</span> (c &gt;= <span class="charliteral">&#39; &#39;</span>)</div><div class="line">          Serial.write(c);</div><div class="line">      }</div><div class="line">      <span class="keywordflow">if</span> (!down)</div><div class="line">        Serial.write(<span class="stringliteral">&quot; UP&quot;</span>);</div><div class="line">      Serial.write(<span class="charliteral">&#39;\n&#39;</span>);</div><div class="line">      <span class="comment">//lastvk = down ? vk : fabgl::VK_NONE;</span></div><div class="line">    <span class="comment">//}</span></div><div class="line">  }</div><div class="line"></div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
